﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GOFconsole
{
    public class Chapter12_Facade //美[fəˈsɑːd] 外表、外观
    {
        public void FacadeTest()
        { 
            //模型
            Facade facade = new Facade();   //由于Facade的作用，客户端可以根本不知道三个子系统类的存在
            facade.MethodA();
            facade.MethodB();

            //Demo
            //用户不需要了解股票，房产等，只需要买基金。股票房产的具体买卖都有基金公司完成。客户端代码很简洁
            Fund jijin = new Fund();    //基金类需要了解所有的股票房产信息，进行投资组合，以备外界调用
            jijin.BuyFund();
            jijin.SellFund();
        }
    }

    #region 模型
    class Facade    //外观类，它需要了解所有的子系统的方法或属性，进行组合，以备外界调用
    {
        SubSystemOne one;
        SubSystemTwo two;
        SubSystemThree three;
        SubSystemFour four;

        public Facade()
        {
            one = new SubSystemOne();
            two = new SubSystemTwo();
            three = new SubSystemThree();
            four = new SubSystemFour();
        }

        public void MethodA()
        {
            Console.WriteLine("方法组A ---");
            one.MethodOne();
            two.MethodTwo();
            four.MethodFour();
        }

        public void MethodB()
        {
            Console.WriteLine("方法组A ---");
            three.MethodThree();
            four.MethodFour();
        }
    }

    class SubSystemOne
    {
        public void MethodOne()
        {
            Console.WriteLine("子系统方法1");
        }
    }
    class SubSystemTwo
    {
        public void MethodTwo()
        {
            Console.WriteLine("子系统方法2");
        }
    }
    class SubSystemThree
    {
        public void MethodThree()
        {
            Console.WriteLine("子系统方法3");
        }
    }
    class SubSystemFour
    {
        public void MethodFour()
        {
            Console.WriteLine("子系统方法4");
        }
    }
    #endregion

    #region Demo(买股票)
    class Fund
    {
        Stock s;
        Realty r;

        public Fund()
        {
            s = new Stock();
            r = new Realty();
        }

        public void BuyFund()
        {
            s.buyStock();
            r.buyRealty();
        }
        public void SellFund()
        {
            s.sellStock();
            r.sellRealty();
        }
    }

    class Stock     //股票类
    {
        public void sellStock()
        {
            Console.WriteLine("卖股票");
        }
        public void buyStock()
        {
            Console.WriteLine("买股票");
        }
    }
    class Realty    //房地产类
    {
        public void sellRealty()
        {
            Console.WriteLine("卖房地产");
        }
        public void buyRealty()
        {
            Console.WriteLine("买房地产");
        }
    }

    #endregion
}
